package com.aiti.lulian.service.newCard;

import com.aiti.lulian.entity.newCard.CardMessage;
import com.aiti.lulian.mapper.newCard.CardMessageMapper;
import com.aiti.lulian.service.CardMessageService;
import com.aiti.lulian.vo.newCard.CardMessageVo;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardMessageServiceImpl extends ServiceImpl<CardMessageMapper, CardMessage> implements CardMessageService {

    @Autowired
    private CardMessageMapper cardMessageMapper;

    @Override
    public int getCount(String cardId) {
        return cardMessageMapper.selectMessageCount(cardId);
    }

    @Override
    public List<CardMessageVo> getPage(Page<CardMessage> page, String cardId) {
        return cardMessageMapper.selectCardMessagePage(page, cardId);
    }

    @Override
    public void readAllMessage(CardMessage cardMessage) {
        this.update(new LambdaUpdateWrapper<CardMessage>().eq(CardMessage::getReceiverCardId, cardMessage.getCardId()).eq(CardMessage::getIsRead, 0).set(CardMessage::getIsRead, 1));
    }
}
